package com.utils.jackson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.f.manage.面向对象.superr.Person;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.utils.jackson.bean.ResponseBean;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.TimeUnit;

public class jacksonTest {
    Logger LOGGER = LoggerFactory.getLogger(jacksonTest.class);
    public static void main(String[] args) {

        String exist = "1";
        if (exist  !=null && "1".equals(exist)){
            System.out.println(12111);
        }else{
            System.out.println("tttt");
        }
        if (exist  == null || !"1".equals(exist)){
            System.out.println("tttt");
        }else{
            System.out.println(12111);
        }

//
//        String res = "{\"code\":200,\"msg\":\"张三\",\"data\":Set[{\"age\":23,\"name\":\"张三\"}]}";
//       JsonNode obj = JSONUtils.parseObject(res);
//        int aa = JSONUtils.getInt(obj,"code");
//      System.out.println(12);
//        JSONObject device = new JSONObject();
//
//        device.put("productId", 12);
//
//        JSONObject other = new JSONObject();
//        other.put("autoObserver", "1212");
//
//        device.put("other", other);
//
//        String deviceStr = JSONObject.toJSONString(device);
        // {"other":{"autoObserver":"1212"},"productId":12}
//        System.out.println(12);
//        String res = "{\"code\":200,\"msg\":\"张三\",\"data\":[{\"age\":23,\"name\":\"张三\"}]}";
//        JsonNode obj = JSONUtils.parseObject(res);
//        ArrayNode list = JSONUtils.parseArray(obj.get("data").toString());
        //        res = " ";
//        ResponseBean<ArrayList> responseBean = JSONUtils.parseObject(res, ResponseBean.class);
//        if (responseBean != null && 200 == responseBean.getCode()){
//            String jsonStr = JSONUtils.toJSONString(responseBean.getData());
//            jsonStr = " ";
//            List<Person> list = JSONUtils.parseArray(jsonStr,Person.class);
//            System.out.println(12);
//        }

//        String getState = "{\"age\":23,\"name\":\"张三\"}";
////        getState = "{\"Data\":{\"age\":23,\"IsOnline\":1}}";
//
//        JsonNode jsonData = JSONUtils.parseObject(null);
//
//        String json = JSONUtils.toJSONString(null);
//        System.out.println(12);


//        String param = "{\"name\":23,\"payload\":{\"co2\":23},\"deviceId\":\"111\"}";
//        String str = "{\"@type\":\"com.zlwy.system.api.model.LoginUser\",\"expireTime\":1747535195423,\"ipaddr\":\"36.41.69.224\",\"loginTime\":1674959195423,\"passTime\":1677548627000,\"permissions\":[\"system:user:resetPwd\",\"system:post:list\",\"/screen_tb/videoSurve:list\",\"system:menu:query\",\"system:dept:remove\",\"system:menu:list\",\"manage:trace:list\",\"system:dict:edit\",\"system:user:query\",\"system:operlog:query\",\"system:operlog:export\",\"system:user:add\",\"system:notice:remove\",\"system:user:export\",\"system:role:remove\",\"manage:land:add\",\"system:dept:query\",\"system:dict:list\",\"system:logininfor:remove\",\"manage:land:query\",\"system:notice:list\",\"system:dict:query\",\"system:notice:query\",\"system:notice:edit\",\"system:post:edit\",\"system:logininfor:query\",\"manage:device:add\",\"system:dict:export\",\"system:post:query\",\"system:post:remove\",\"system:operlog:remove\",\"system:config:edit\",\"manage:crop:query\",\"system:user:remove\",\"system:config:list\",\"system:menu:add\",\"manage:device:remove\",\"system:role:list\",\"manage:land:remove\",\"manage:crop:edit\",\"manage:land:edit\",\"system:user:import\",\"system:dict:remove\",\"system:user:edit\",\"system:post:export\",\"system:config:export\",\"system:role:edit\",\"system:dept:list\",\"system:config:query\",\"manage:crop:export\",\"manage:land:list\",\"system:role:add\",\"manage:crop:remove\",\"manage:device:list\",\"system:menu:remove\",\"system:dict:add\",\"system:operlog:list\",\"/screen_tb/commoditySource:list\",\"system:logininfor:export\",\"system:dept:edit\",\"system:post:add\",\"system:user:list\",\"system:notice:add\",\"manage:crop:list\",\"manage:device:edit\",\"system:role:export\",\"system:config:add\",\"manage:device:query\",\"manage:device:export\",\"manage:crop:add\",\"manage:land:export\",\"system:logininfor:list\",\"/screen_tb/DemonstrationPark:list\",\"system:role:query\",\"system:menu:edit\",\"system:dept:add\",\"system:config:remove\"],\"roles\":[\"tb\"],\"sysUser\":{\"admin\":false,\"avatar\":\"\",\"createBy\":\"admin\",\"createTime\":1672306380000,\"delFlag\":\"0\",\"dept\":{\"area\":\"610524\",\"children\":[],\"city\":\"6105\",\"deptId\":261,\"deptName\":\"星光产业园葡萄种植生产区\",\"orderNum\":\"8\",\"params\":{\"@type\":\"java.util.HashMap\"},\"parentId\":257,\"province\":\"61\",\"status\":\"0\",\"street\":\"610524104\"},\"deptId\":261,\"email\":\"\",\"loginIp\":\"\",\"nickName\":\"合阳星光产业园葡萄种植账号\",\"params\":{\"@type\":\"java.util.HashMap\"},\"passTime\":1677548627000,\"password\":\"$2a$10$aJ4B5U/.t5FQorles3lElemE6.lGFqgoW9WzLgdjx7Gx3HWckliHK\",\"phonenumber\":\"\",\"roles\":[{\"admin\":false,\"dataScope\":\"4\",\"deptCheckStrictly\":false,\"flag\":false,\"menuCheckStrictly\":false,\"params\":{\"@type\":\"java.util.HashMap\"},\"roleId\":46,\"roleKey\":\"tb\",\"roleName\":\"合阳农场管理员\",\"roleSort\":\"50\",\"status\":\"0\"}],\"sex\":\"0\",\"status\":\"0\",\"userId\":202212290933000268,\"userName\":\"hyxgptad001\"},\"token\":\"853050b1-4a0e-4ece-9a8b-9c40c3cf6424\",\"userid\":202212290933000268,\"username\":\"hyxgptad001\"}";
//        JsonNode json = JSONUtils.parseObject(str);
//        String payload = JSONUtils.getObj(json,"payload");
//
//        if (json.has("name2")) {
//            System.out.println(121);
//        }
//        HashMap<String, Double> map = JSONUtils.parseObject(payload, HashMap.class);
//        System.out.println(12);

//      String param = "{\"name\":23,\"messageType2\":\"deviceOnlineOfflineReport\",\"eventType\":\"1\",\"deviceId\":\"111\"}";
//        JsonNode json = JSONUtils.parseObject(param);
//        //获取AEP数据
//        try {
//            //获取设备是否在线
//            if (!Objects.isNull(JSONUtils.getString(json,"messageType")) && !"".equals(JSONUtils.getString(json,"messageType"))) {
//                //判断消息类型
//                if ("deviceOnlineOfflineReport".equals(JSONUtils.getString(json,"messageType"))) {
//                    //上线：1，下线：0
//                    String eventType = JSONUtils.getString(json,"eventType");
//                    //获取产品id
//                    String deviceId = JSONUtils.getString(json,"deviceId");
//                    System.out.println(12);
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//       String getState = "{\"age\":23,\"name\":\"张三\"}";
//      getState = "{\"Data\":{\"age\":23,\"IsOnline\":1}}";
//        JSONObject json = JSON.parseObject(getState);
//        String data = json.getString("Data");
//        JSONObject jsonData = JSON.parseObject(data);
//        if (!Objects.isNull(jsonData.getString("IsOnline"))) {
//            Boolean isOnline = Boolean.parseBoolean(jsonData.getString("IsOnline"));
//            System.out.println(12);
//        }
//        System.out.println(12);
//            String res = "{\"code\":200,\"msg\":\"张三\",\"data\":\"张三5555555\"}";
//            ResponseBean<String> responseBean= JSONUtils.parseObject(res,ResponseBean.class);
//            if(responseBean!=null&& 200 == responseBean.getCode()) {
//                String str = responseBean.getData();
//                System.out.println(12);
//            }
//            ResponseBean<ArrayList> responseBean = JSONUtils.parseObject(res, ResponseBean.class);
//            if (responseBean != null && 200 == responseBean.getCode()) {
//                List<Person> list = responseBean.getData();
//                System.out.println(12);
//            }

//            ResponseBean<JSONObject> responseBean = JSON.parseObject(res, ResponseBean.class);
//            if (responseBean != null && 200 == responseBean.getCode()) {
//
//                String jsonStr = JSONObject.toJSONString(responseBean.getData());
//                List<Person> list = JSONObject.parseArray(jsonStr, Person.class);
//                System.out.println(12);
//            }
//            Person person = JSONUtils.parseObject(getState,Person.class);
//            System.out.println(12);
//            JsonNode node = JSONUtils.parseObject(getState);
//            JsonNode jsonData = node.get("Data");
//            if (!Objects.isNull(jsonData.get("IsOnline"))) {
//                Boolean isOnline = Boolean.parseBoolean(jsonData.get("IsOnline").asText());
//                System.out.println(12);
//            }
//
//
//
//            String getValue = "{\"Data\":[{\"age\":23,\"IsOnline\":1}]}";
//            JsonNode jsonValue = JSONUtils.parseObject(getValue);
//            ArrayNode array = (ArrayNode)jsonValue.get("Data");
//            for (int i = 0; i < array.size(); i++) {
//                JsonNode jsonObject = array.get(i);
//                String value = jsonObject.get("age").asText();
//                System.out.println(12);
//            }
//        try {
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//            System.out.println(12);

    }
}
